package com.jason.quectel.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jason.quectel.R;
import com.jason.quectel.bean.ArticleBean;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @author：Jason
 * @date：2022/3/9 19:35
 * @email：1129847330@qq.com
 * @description:
 */
public class SecondAdapter extends RecyclerView.Adapter<SecondAdapter.SecondHolder> {
    private List<ArticleBean> totallist = new ArrayList<>();

    public void setData(List<ArticleBean> list) {
        totallist.clear();
        totallist.addAll(list);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public SecondHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_second, null, false);
        SecondHolder secondHolder = new SecondHolder(view);
        return secondHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull SecondHolder holder, int position) {
        ArticleBean articleBean = totallist.get(position);
        holder.textView.setText(articleBean.title);
        holder.imageView.setImageResource(articleBean.imageResId);
    }

    @Override
    public int getItemCount() {
        return (totallist == null || totallist.size() <= 0) ? 0 : totallist.size();
    }

    static class SecondHolder extends RecyclerView.ViewHolder {
        private ImageView imageView;
        private TextView textView;

        public SecondHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.iv_second);
            textView = itemView.findViewById(R.id.tv_second);
        }
    }
}